#include <stdio.h>

void select_sort(int* nums, int length);
void print_array(int* array, int length);


int main(int argc, char* argv[])
{
  FILE *rfp;
  char str[80];
  int nums[100];
  if((rfp = fopen(argv[1], "r")) == NULL)
  {
    printf("文件打开失败！\n");
    return -1;
  }
  int length = 0;
  while(fgets(str, 80, rfp) != NULL)
  {
    sscanf(str, "%d", &nums[length]);
    length++;
  }
  select_sort(nums, length);
  print_array(nums, length);
  fclose(rfp);
  return 0;
}


void print_array(int* array, int length)
{
  for(int i = 0; i < length; i++)
  {
    printf("%d ", array[i]);
  }
  printf("\n");
}


void select_sort(int* nums, int length)
{
  for(int i = 0; i < length - 1; i++)
  {
    int k = i;
    for(int j = i; j < length; j++)
    {
      if(nums[j] < nums[k])
      {
        k = j;
      }
    }
    int tmp = nums[i];
    nums[i] = nums[k];
    nums[k] = tmp;
  }
}
